From d9bada6f0be13d2c4b569e51bdf571ee9e0d0d34 Mon Sep 17 00:00:00 2001
From: Fuwn <contact@fuwn.me>
Date: Fri, 29 Dec 2023 22:05:21 -0800
Subject: feat(badges): double click to delete badge

---
 src/routes/user/[user]/badges/+page.svelte | 19 +++++++++++++++++--
 1 file changed, 17 insertions(+), 2 deletions(-)

(limited to 'src/routes/user/[user]/badges/+page.svelte')

diff --git a/src/routes/user/[user]/badges/+page.svelte b/src/routes/user/[user]/badges/+page.svelte
index dde0523b..febf5bdf 100644
--- a/src/routes/user/[user]/badges/+page.svelte
+++ b/src/routes/user/[user]/badges/+page.svelte
@@ -17,6 +17,7 @@
 	let badges: Badge[] | null = null;
 	let dark = true;
 	let transparent = false;
+	let confirmDelete = 0;
 
 	onMount(async () => {
 		// socket.on('badges', (message) => (badges = message));
@@ -70,6 +71,20 @@
 	};
 
 	const removeBadge = (badge: Badge) => {
+		if (!badge.id) return;
+
+		if (confirmDelete === badge.id * 2) {
+			confirmDelete = 0;
+		} else if (confirmDelete / 4 === badge.id) {
+			confirmDelete = badge.id * 2;
+
+			return;
+		} else {
+			confirmDelete = badge.id * 2;
+
+			return;
+		}
+
 		fetch(`/api/badges?id=${badge.id}`, {
 			method: 'DELETE'
 		}).then(() => {
@@ -154,8 +169,8 @@
 
 	{#if editMode && isOwner}
 		<p>
-			Delete mode is enabled. Click on an image to delete it. There is no confirmation, so be
-			careful!
+			Edit mode is enabled. Click on an image <b>twice</b> to delete it. There is no confirmation, so
+			be careful!
 		</p>
 
 		{#if error}
-- 
cgit v1.2.3

